package com.uhylab.uhuvinetest.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.base.UHBaseActivity;
import com.uhylab.uhuvinetest.utils.dataclean.DataCleanManager;
import com.uhylab.uhuvinetest.utils.sharedpreutils.SharedPreUtils;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称：Uhylab
 * 类描述：
 * 创建人：xyb
 * 创建时间：16/5/31 14:12
 * 修改人：xyb
 * 修改时间：16/5/31 14:12
 * 修改备注：
 */
public class UHSettingActivity extends UHBaseActivity {


    private static final String CLEAN = "清理成功";
    @BindView(R.id.back)
    ImageView mBack;
    @BindView(R.id.dis_one_re)
    AutoRelativeLayout mSettingMsgRe;
    @BindView(R.id.dis_two_re)
    AutoRelativeLayout mSettingCleanRe;
    @BindView(R.id.logoff)
    AutoRelativeLayout mLogoff;
    @BindView(R.id.setting_clean_exchange)
    TextView mSettingCleanExchange;
    @BindView(R.id.line)
    View mView;
    /**
     * 绑定布局
     *
     * @return int
     */
    @Override
    public int bindLayout() {
        return R.layout.activity_uhsetting;
    }

    /**
     * 初始化布局
     *
     * @param view
     */
    @Override
    public void initView(View view) {
        ButterKnife.bind(this);
    }

    /**
     * 业务处理操作（onCreate方法中调用）
     *
     * @param mContext 当前Activity对象
     */
    @Override
    public void doBusiness(Context mContext) {

        if (!SharedPreUtils.getBoolean(getContext(), "is_Login", false)) {
            mLogoff.setVisibility(View.GONE);
        }

        String size = null;
        try {
            size = DataCleanManager.getCacheSize(getCacheDir());
            mSettingCleanExchange.setText(size);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 暂停恢复刷新相关操作（onResume方法中调用）
     */
    @Override
    public void resume() {
        if (!SharedPreUtils.getBoolean(getContext(), "is_Login", false)) {
            mLogoff.setVisibility(View.GONE);
        }
    }

    /**
     * 销毁、释放资源相关操作（onDestroy方法中调用）
     */
    @Override
    public void destroy() {

    }


    @OnClick({R.id.back, R.id.dis_one_re, R.id.dis_two_re, R.id.logoff})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.dis_one_re:
                Intent informationCenter = new Intent(getContext(), UHInformationActivity.class);
                startActivity(informationCenter);
                break;
            case R.id.dis_two_re:

                DataCleanManager.cleanInternalCache(this);
                try {
                    String size = DataCleanManager.getCacheSize(getCacheDir());
                    mSettingCleanExchange.setText(size);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Toast.makeText(this, CLEAN, Toast.LENGTH_SHORT).show();
                break;
            case R.id.logoff:
                if (!SharedPreUtils.getBoolean(getContext(), "is_Login", false)) {
                    Intent intent = new Intent(this, UHLogonActivity.class);
                    startActivity(intent);
                } else {
                    SharedPreUtils.setBoolean(getContext(), "is_Login", false);
                    SharedPreUtils.setString(getContext(), "user_tel", "");
                    SharedPreUtils.setString(getContext(), "user_password", "");
                    SharedPreUtils.setString(getContext(), "user_token", "");
                    UHSettingActivity.this.setResult(2);
                    finish();
                }
                break;
        }
    }

}
